<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="copyright" content="Tencent"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
	<title>酷门户</title>
	<link href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/public.css" />
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/activity.css" />
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/marketing.css" />
     <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/style_list.css" /> 
     <link href="<%=path%>/favicon.ico" rel="shortcut icon">
     <style>
     	.k_content dl dd p i.k_red_over {
    background: #fe7469;
}
     </style>
</head>
<body>
    <div class="k_phone">
        <dl class="k_title fix">
            <dt><img id="micro_pic" style="width: 133px;height: 109px" src="<%=path%>/images/marketing/s_img.png" /></dt>
            <dd>
                <h2 id="name">好伦哥自助披萨（马家堡店）</h2>
                <ol id="tag" class="fix">
                    <li>自助</li>
                    <li>披萨</li>
                    <li>烧烤</li>
                </ol>
              <%--   <span>
                    <img src="<%=path%>/images/marketing/star.png" />
                    <img src="<%=path%>/images/marketing/star.png" />
                    <img src="<%=path%>/images/marketing/star.png" />
                    <img src="<%=path%>/images/marketing/star.png" />
                    <img src="<%=path%>/images/marketing/star.png" />
                    9.8分
                </span> --%>
                <p id="business_hours">营业时间：10：00-14：30周一至周日 17：00-22：00周一至周日</p>
            </dd>
        </dl>
        <ol class="k_detailed fix">
            <li><img src="<%=path%>/images/marketing/icon_address.png" /> &nbsp; <span id="address">北京市大兴区亦庄 开发区数码庄园</span></li>
            <li><img src="<%=path%>/images/marketing/icon_phone.png" /> &nbsp;<span id="phone">010-4635271&nbsp;&nbsp;010-3746283</span></li>
        </ol>
        <ul class="k_nav fix">
            <li class="on" style="width:50%;"><a href="javascript:;" id = "bm_huoshi">活动进行时</a></li>
            <!-- <li><a href="javascript:;">网友点评</a></li> -->
            <li style="width:50%;"><a href="javascript:;" id="bm_lishihuo">历史活动</a></li>
        </ul>
        <div class="k_cut">
            <ul class="surrent">
                <div class="k_content" id = "bm_zheng">
                   <%-- <dl class="fix" id = "bm_jinshi">
                         <dt><img src="<%=path%>/images/marketing/s_img_bg.png" /></dt>
                        <dd>
                            <p>充值1000赠500代金券<i>进行中</i></p>
                            <span>
                                <img src="<%=path%>/images/marketing/star.png" />
                                <img src="<%=path%>/images/marketing/star.png" />
                                <img src="<%=path%>/images/marketing/star.png" />
                                <img src="<%=path%>/images/marketing/star.png" />
                                <img src="<%=path%>/images/marketing/star_no.png" />
                                9.8分
                            </span>
                            <em>有效期至2017-12-30</em>
                        </dd>
                    </dl>            
                    <ol class="fix" id = "bm_ren">
                          <li>菜品卫生</li>
                        <li>菜量足</li>
                        <div id = "bm_avti">
                            <li class="s_partake">17263人参与</li>
                            <li class="s_like"><img src="<%=path%>/images/marketing/dianzan.png" />17263</li>
                        </div> 
                    </ol>  --%>      
                </div>
                 <%-- <div class="k_comment fix">
                    <h4>点评(689)</h4>
                    <div>
                        <dl>
                            <dt><img src="<%=path%>/images/marketing/s_pic.png" /></dt>
                            <dd>
                                <p>奔跑的苹果</p>
                                <span>
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                </span>
                            </dd>
                        </dl>
                        <p class="k_pl">每次活动都必须参加，很喜欢这样的活动，非常优惠，似的，非常优惠非常一瓶</p>
                    </div>
                    <div>
                        <dl>
                            <dt><img src="<%=path%>/images/marketing/s_pic.png" /></dt>
                            <dd>
                                <p>奔跑的苹果</p>
                                <span>
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                </span>
                            </dd>
                        </dl>
                        <p class="k_pl">再来点活动</p>
                        <p class="k_hf">
                            <span>商家回复:</span>好的商家!
                            <i><img src="<%=path%>/images/marketing/triangle.png" /></i>
                        </p>
                    </div>
                    <a href="s22.html"><img src="<%=path%>/images/marketing/icon-dp.png" />&nbsp;&nbsp;写评论</a>
                </div> --%>
            </ul>
            <%--<ul>
                 <div class="k_comment fix">
                    <h4>点评(689)</h4>
                    <div>
                        <dl>
                            <dt><img src="<%=path%>/images/marketing/s_pic.png" /></dt>
                            <dd>
                                <p>奔跑的苹果</p>
                                <span>
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                </span>
                            </dd>
                        </dl>
                        <p class="k_pl">每次活动都必须参加，很喜欢这样的活动，非常优惠，似的，非常优惠非常一瓶</p>
                    </div>
                    <div>
                        <dl>
                            <dt><img src="<%=path%>/images/marketing/s_pic.png" /></dt>
                            <dd>
                                <p>奔跑的苹果</p>
                                <span>
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                    <img src="<%=path%>/images/marketing/star.png" />
                                </span>
                            </dd>
                        </dl>
                        <p class="k_pl">再来点活动</p>
                        <p class="k_hf">
                            <span>商家回复:</span>好的商家!
                            <i><img src="<%=path%>/images/marketing/triangle.png" /></i>
                        </p>
                    </div>
                    <a href="s22.html"><img src="<%=path%>/images/marketing/icon-dp.png" />&nbsp;&nbsp;写评论</a>
                </div> 
            </ul>--%>
            <ul class="surrent">
                <div class="k_content" id="bm_lishi">
                    <%-- <dl class="fix">
                        <dt><img src="<%=path%>/images/marketing/s_img_bg.png" /></dt>
                        <dd>
                            <p>充值1000赠500代金券<i>进行中</i></p>
                            <span>
                                <img src="<%=path%>/images/marketing/star.png" />
                                <img src="<%=path%>/images/marketing/star.png" />
                                <img src="<%=path%>/images/marketing/star.png" />
                                <img src="<%=path%>/images/marketing/star.png" />
                                <img src="<%=path%>/images/marketing/star_no.png" />
                                9.8分
                            </span>
                            <b><img src="<%=path%>/images/marketing/ygq.png" /></b>
                        </dd>
                    </dl>            
                    <ol class="fix">
                        <li>菜品卫生</li>
                        <li>菜量足</li>
                        <div>
                            <li class="s_partake">17263人参与</li>
                            <li class="s_like"><img src="<%=path%>/images/marketing/dianzan.png" />17263</li>
                        </div>
                    </ol>        --%>
                </div> 
            </ul>
        </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
    <script>
        $('.k_nav li').click(function(){
            $(this).addClass('on').siblings().removeClass();
            var index = $(this).index();
            $('.k_cut ul').removeClass('surrent').eq(index).addClass('surrent');
        });
    </script>
    <script type="text/javascript">
    var status;
	var access_token=$.cookie('access_token');
	var cid;
	var uid=$.cookie('uid');
	
	var store_id;
	var pageSize=5;
	var startIndex=0;
    var currentPage = 1;
    var pageCount = 0;
    //点击活动进行时显示
    $('#bm_huoshi').click(function(){
    	status = "1";
    	activting();
    	
    });
    
    //点击历史活动显示
     $('#bm_lishihuo').click(function(){
    	status = "0";
    	activting();
    }); 
    //方法开始运行
   $(function(){   	
	  status = "1";
	  cid=getQueryString("cid");
	  getStoreInfo();
	  getWeinInfo();
      
    });   
    //获取门店信息
    function getStoreInfo(){
    	var url = "<%=path%>/api/microportal/detail";
    	$.post(url,{
    	"access_token" : access_token,
 		"cid" : cid,
 		"uid" : uid,
    	},function(data){
    		
    		if(data.error_code == "0"){
    			
    			console.log(data.data.name);
    			 $('#address').html(data.data.address);
    			 $("#name").html(data.data.name);
    			 $("#business_hours").text(data.data.business_hours);
    			 $('#phone').html(data.data.phone);
    			 
    			 $(document).attr("title",data.data.name);
    			 
    			 var tag=(data.data.tag).split(",");
    			 var htmlTag='';
    			 for(var i=0;i<tag.length;i++){
    				htmlTag+='<li>'+tag[i]+'</li>';
    			 }
    			 $("#tag").html(htmlTag);
    			 
    			 
    			 $("#micro_pic").attr("src",data.data.pic);
    			 
    			 store_id=data.data.store_id;
    			 console.log("store_id------->"+store_id);
    			 activting();  	
    		}else{
    			/* showDialog("无微门户信息"); */
    		}
    	}); 
    }
    
    
    //活动进行时
    function activting(){  

    	var url = "<%=path%>/activity/activiting";
    	$.post(url,{
    		"cid" :cid,
    		"uid" : uid,
    		"access_token" :access_token,
    		"startIndex" : startIndex,
    		"page_size" : pageSize, 
    		"status" : status,
    		"store_id":store_id,
    	},function(data){   		
    		  
    		console.log(data.error_code);
    		
  /*   		if(status == "1"){
    			activtingHtml(data.data);		
    		}else{
    			historicalHtml(data.data);
    		} */
    		if(status == "1"){
    			activtingHtml(data.data);		
    			page(data.totalCount);
    		}else{
    			console.log("data.totalCount------>"+data.totalCount);
    			historicalHtml(data.data);
    			page2(data.totalCount);
    		}    		    		
    	});
    }  
    
    //进行时活动    
    function activtingHtml(data){       	
    	var html = '';  	   	
    	for(var i=0;i<data.length;i++){    		
    		var dataStr = data[i].start_date;    	
    		var dayCount = data[i].effective_day;       		
    		html += '<dl class="fix"><dt><img style="height:90px;" src="'+data[i].head_pic+'" />';
        	html += '</dt><dd><p><a href="'+data[i].web_url+'"><font color=black>'+data[i].name+'</font></a><i>进行中</i></p>';
        	html += '<em>'+(data[i].end_time2==undefined || data[i].end_time2=="" ?"":"有效期至:"+data[i].end_time2)+'</em>';   
        	html += '<em>领取数'+data[i].total+'/总数'+data[i].coupon_number+'</em>';   
        	html += '</dd></dl><ol class="fix">';
          	<%-- html += '<div id = "bm_avti"><li class="s_partake">'+data[i].total +'人参与</li><li class="s_like"><img class="s_dianzan_img" src="<%=path%>/images/marketing/dianzan.png" _id="1"/>'+data[i].browseNum+'</li></div>';--%>          	
          	html += '</ol>';        	        	
       }    	
    	$('#bm_zheng').html(html); 	
    	var pagesHtml='';
		pagesHtml+='<div class="m_xpages" style="width: 100%; margin: 0;">';
		pagesHtml+='<div class="mian">';
		pagesHtml+='<span>显示行数</span> <select><option>5</option>';
		pagesHtml+='<option>10</option>';
		pagesHtml+='<option>20</option></select> <span>共0条</span> <span>0/0页</span>';
		pagesHtml+='<a href="javascript:;" class="prev">上一页</a> <a href="javascript:;"';
		pagesHtml+='class="next">下一页</a> <span>前往</span> <input type="text" value="1"';
		pagesHtml+='class="text"> <span>页</span>';
		pagesHtml+='</div></div>';
		$('#bm_zheng').append(pagesHtml);
    }
    
    //历史活动
    function historicalHtml(data){    
    	var html = '';
    	for(var i=0;i<data.length;i++){
    		console.log("=====>"+data[i].name);
    		html+= '<dl class="fix"><dt><img style="height:90px;" src="'+data[i].head_pic+'" />';
    		html+= '</dt><dd><p><a href="'+data[i].web_url+'"><font color=black>'+data[i].name+'</font></a><i class="k_red_over">已结束</i></p>';
<%--     		html+= '<span><img src="<%=path%>/images/marketing/star.png" /><img src="<%=path%>/images/marketing/star.png" />';
    		html+= '<img src="<%=path%>/images/marketing/star.png" /><img src="<%=path%>/images/marketing/star.png" />';
    		html+= '<img src="<%=path%>/images/marketing/star_no.png" />9.8分</span>'; --%>
    		html+= '<b><img src="<%=path%>/images/marketing/ygq.png" /></b>';
        	html+= '<em>领取数'+data[i].total+'/总数'+data[i].coupon_number+'</em>';  
    		html+= '</dd></dl><ol class="fix"><div>';
    		<%-- html+= '<li class="s_partake">'+data[i].total+'人参与</li><li class="s_like"><img class="s_dianzan_img" src="<%=path%>/images/marketing/dianzan.png" _id="1"/>'+data[i].browseNum+'</li>'; --%>  
  		    html+= '</div></ol>';
    	}  
    	console.log(html);
    	$('#bm_lishi').html(html); 
    	var pagesHtml='';
		pagesHtml+='<div class="m_xpages test" style="width: 100%; margin: 0;">';
		pagesHtml+='<div class="mian">';
		pagesHtml+='<span>显示行数</span> <select><option>5</option>';
		pagesHtml+='<option>10</option>';
		pagesHtml+='<option>20</option></select> <span>共0条</span> <span>0/0页</span>';
		pagesHtml+='<a href="javascript:;" class="prev test2">上一页</a> <a href="javascript:;"';
		pagesHtml+='class="next test3">下一页</a> <span>前往</span> <input type="text" value="1"';
		pagesHtml+='class="text"> <span>页</span>';
		pagesHtml+='</div></div>';
		$('#bm_lishi').append(pagesHtml);
    } 
    
    $(".m_xpages select").change(function(){
 		pageSize = Number($(this).val());		 		
 		activting();
 	});
 	
	 $(document).on('click', '.m_xpages a.prev', function() {
	
 	/* $(".m_xpages a.prev").click(function(){	 		 */
 		if(currentPage > 1){
 			currentPage--;
 			startIndex -= pageSize;	 	
 			activting();
 		}
 	});
 	 $(document).on('click', '.m_xpages a.next', function() {
 	/* $(".m_xpages a.next").click(function(){ */
 		if(currentPage < pageCount){
 			currentPage++;
 			startIndex += pageSize;	
 			activting();
 		}
 	});
 	
 	$(".m_xpages :text").keyup(function(e){
		if(e.keyCode==13){
			var pageGo = $(this).val();
			if(/^[0-9]+$/.test(pageGo)){
				pageGo = Number(pageGo);
				if(pageGo<1 || pageGo>pageCount){
					showDialog('请输入合法页数');
				}else if(pageGo != currentPage){
					startIndex = (pageGo -1) * pageSize ;	
					activting();
				}
			}else{
				showDialog('请输入合法页数');
			}
		}
	});
function page(totalCount) {
	pageCount = totalCount/pageSize;
		if (totalCount % pageSize > 0)
			pageCount++;
		pageCount = parseInt(pageCount);
		currentPage =  startIndex / pageSize + 1;
		currentPage = parseInt(currentPage);
		if(currentPage == 1){
			$(".prev").addClass("pageDisable");
		}else{
			$(".prev").removeClass("pageDisable");
		}
		
		if(currentPage == pageCount || pageCount == 0){
			$(".next").addClass("pageDisable");
		}else{
			$(".next").removeClass("pageDisable");
		}
		
		$(".m_xpages>.mian>span:eq(1)").text('共'+totalCount+'条');
		$(".m_xpages>.mian>span:eq(2)").text(currentPage+'/'+pageCount+'页');
}

function page2(totalCount) {
	pageCount = totalCount/pageSize;
		if (totalCount % pageSize > 0)
			pageCount++;
		pageCount = parseInt(pageCount);
		currentPage =  startIndex / pageSize + 1;
		currentPage = parseInt(currentPage);
		if(currentPage == 1){
			$(".test2").addClass("pageDisable");
		}else{
			$(".test2").removeClass("pageDisable");
		}
		
		if(currentPage == pageCount || pageCount == 0){
			$(".test3").addClass("pageDisable");
		}else{
			$(".test3").removeClass("pageDisable");
		}
		$(".test>.mian>span:eq(1)").text('共'+totalCount+'条');
		$(".test>.mian>span:eq(2)").text(currentPage+'/'+pageCount+'页');
}
    
    
    
	 //活动开始时间+有效天数
	function dateAddDays(dataStr,dayCount){
		var strdate=dataStr; //日期字符串
	    var isdate = new Date(strdate.replace(/-/g,"/"));  //把日期字符串转换成日期格式
	    isdate = new Date((isdate/1000+(86400*dayCount))*1000);  //日期加1天
	    var pdate = isdate.getFullYear()+"-"+(isdate.getMonth()+1)+"-"+(isdate.getDate()); //把日期格式转换成字符串		   
	    return pdate;	   
	}    
    function getQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null)
			return unescape(r[2]);
		return null;
	}
    
    
    var timestamp;
	 var signature;
	 var nonceStr;
	 var link_url;
	 var appid;
	    function getWeinInfo(){
	    	 web_url = window.location.href.split('#')[0];  
	    	/* web_url = web_url.replace(/\&/g, '%26');  */
	    	console.log("web_url------->"+web_url);
	    	/* web_url=encodeURIComponent(web_url); */
	    	var url="<%=path%>/api/weixin/share";
			$.post(url, {
				"url" : web_url,
			}, function(data) {
				
				timestamp=data.timestamp;
				signature=data.signature;
				nonceStr=data.nonceStr;
				link_url=data.url;
				console.log("substr----->"+link_url);
				console.log("timestamp------->"+timestamp);
				console.log("signature------->"+signature);
				console.log("nonceStr------->"+nonceStr);
				var reg = new RegExp("%26","g");
				link_url=link_url.replace(reg,"&");
				console.log("link_url"+link_url);
				appid=data.appId;
				config();
			});
	    }
	    
	    function config(){
	    	wx.config({
		        debug: false,
		        appId: appid,
		        timestamp: timestamp,
		        nonceStr: nonceStr,
		        signature: signature,
		        jsApiList: [
		          'checkJsApi',
		          'onMenuShareTimeline',
		          'onMenuShareAppMessage',
		          'onMenuShareQQ',
		          'onMenuShareWeibo'
		        ]
		    });
	    	console.log("config--------------->");
	    	
	    	
	    	 wx.ready(function () {
	 	    	console.log("ready----------->");
	 	    	  // 1 判断当前版本是否支持指定 JS 接口，支持批量判断
	 	    	 /*  document.querySelector('#checkJsApi').onclick = function () {
	 	    	    
	 	    	  }; */
	 	    	  wx.checkJsApi({
	 	    	      jsApiList: [
	 	    	        'getNetworkType',
	 	    	        'previewImage'
	 	    	      ],
	 	    	      success: function (res) {
	 	    	        /* console.log(JSON.stringify(res)); */
	 	    	      }
	 	    	    });
	 	    	  
	 	    	  // 2. 分享接口
	 	    	  // 2.1 监听“分享给朋友”，按钮点击、自定义分享内容及分享结果接口
	 	    	
	 	    	   /*  document.querySelector('#onMenuShareAppMessage').onclick = function () { */
	 				    wx.onMenuShareAppMessage({
	 				      title: share_title,
	 				      desc: share_content,
	 				      link: link_url,
	 				      imgUrl: encodeURI(share_pic),
	 				      trigger: function (res) {
	 				      },
	 				      success: function (res) {
	 				      },
	 				      cancel: function (res) {
	 				      },
	 				      fail: function (res) {
	 				        /* alert(JSON.stringify(res)); */
	 				      }
	                 });
	 	    	
	 				   wx.onMenuShareTimeline({
	 					  title: share_title,
	 				      desc: share_content,
	 				      link: link_url,
	 				      imgUrl: share_pic,
	 	 	    	      trigger: function (res) {
	 	 	    	      },
	 	 	    	      success: function (res) {
	 	 	    	      },
	 	 	    	      cancel: function (res) {
	 	 	    	      },
	 	 	    	      fail: function (res) {
	 	 	    	        alert(JSON.stringify(res));
	 	 	    	      }
	 	 	    	    });
	 				   wx.onMenuShareQQ({
	 					  title: share_title,
	 				      desc: share_content,
	 				      link: link_url,
	 				      imgUrl: share_pic,	 				      
	 				      trigger: function (res) {
	 				      },
	 				      complete: function (res) {
	 				        /* alert(JSON.stringify(res)); */
	 				      },
	 				      success: function (res) {
	 				      },
	 				      cancel: function (res) {
	 				      },
	 				      fail: function (res) {
	 				        /* alert(JSON.stringify(res)); */
	 				      }
	 				    });
	 	    	   
	 	    	  });
	    }
    
    
    
    
    
    
    </script>
</body>
</html>